#include <cctype>
#include <cstdio>
#include <cstring>

const int N = 4;
int n;
int read[N][10];
char opt[10005];

struct Surface {
  int s[N][N];
  int *res[N];

  int **getLine(int i, bool vert, bool dir) {
    if (vert) {
      if (dir)
        for (int j = 1; j <= 3; ++j) res[j] = &s[j][i];
      else
        for (int j = 3; j; --j) res[3 - j + 1] = &s[j][i];
    } else {
      if (dir) {
        for (int j = 1; j <= 3; ++j) res[j] = &s[i][j];
      } else
        for (int j = 3; j; --j) res[3 - j + 1] = &s[i][j];
    }
    return res;
  }

  inline void rotate(bool dir) {
    int tmp[N][N];
    int row = 1, col = 1;
    memcpy(tmp, s, sizeof(s));
    if (dir) {  // dir == true 顺时针
      for (int j = 3; j; --j, ++row) {
        col = 1;
        for (int i = 1; i <= 3; ++i, ++col) { s[i][j] = tmp[row][col]; }
      }
    } else {
      for (int j = 1; j <= 3; ++j, ++row) {
        col = 1;
        for (int i = 3; i; --i, ++col) { s[i][j] = tmp[row][col]; }
      }
    }
  }
} F, L, R, U, B, D;

inline void rotateF(bool dir) {
  F.rotate(dir);
  static int tmp[4], **l, **r, **d, **u;
  u = U.getLine(3, false, true);
  l = L.getLine(3, true, false);
  r = R.getLine(1, true, true);
  d = D.getLine(1, false, false);
  for (int i = 1; i <= 3; ++i) tmp[i] = *u[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *l[i], *l[i] = *d[i], *d[i] = *r[i], *r[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *r[i], *r[i] = *d[i], *d[i] = *l[i], *l[i] = tmp[i];
    }
  }
}

inline void rotateL(bool dir) {
  L.rotate(dir);
  static int tmp[4], **b, **f, **d, **u;
  u = U.getLine(1, true, true);
  b = B.getLine(1, true, true);
  f = F.getLine(1, true, true);
  d = D.getLine(1, true, true);
  for (int i = 1; i <= 3; ++i) tmp[i] = *u[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *b[i], *b[i] = *d[i], *d[i] = *f[i], *f[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *f[i], *f[i] = *d[i], *d[i] = *b[i], *b[i] = tmp[i];
    }
  }
}

inline void rotateR(bool dir) {
  R.rotate(dir);
  static int tmp[4], **b, **f, **d, **u;
  u = U.getLine(3, true, false);
  b = B.getLine(3, true, false);
  f = F.getLine(3, true, false);
  d = D.getLine(3, true, false);
  for (int i = 1; i <= 3; ++i) tmp[i] = *u[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *f[i], *f[i] = *d[i], *d[i] = *b[i], *b[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *b[i], *b[i] = *d[i], *d[i] = *f[i], *f[i] = tmp[i];
    }
  }
}

inline void rotateB(bool dir) {
  B.rotate(dir);
  static int tmp[4], **l, **r, **d, **u;
  u = U.getLine(1, false, false);
  r = R.getLine(3, true, false);
  l = L.getLine(1, true, true);
  d = D.getLine(3, false, true);
  for (int i = 1; i <= 3; ++i) tmp[i] = *u[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *r[i], *r[i] = *d[i], *d[i] = *l[i], *l[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *l[i], *l[i] = *d[i], *d[i] = *r[i], *r[i] = tmp[i];
    }
  }
}

inline void rotateU(bool dir) {
  U.rotate(dir);
  static int tmp[4], **b, **l, **f, **r;
  l = L.getLine(1, false, false);
  b = B.getLine(3, false, true);
  f = F.getLine(1, false, false);
  r = R.getLine(1, false, false);
  for (int i = 1; i <= 3; ++i) tmp[i] = *b[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *b[i] = *l[i], *l[i] = *f[i], *f[i] = *r[i], *r[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *b[i] = *r[i], *r[i] = *f[i], *f[i] = *l[i], *l[i] = tmp[i];
    }
  }
}

inline void rotateD(bool dir) {
  D.rotate(dir);
  static int tmp[4], **b, **l, **f, **r;
  f = F.getLine(3, false, true);
  b = B.getLine(1, false, false);
  l = L.getLine(3, false, true);
  r = R.getLine(3, false, true);
  for (int i = 1; i <= 3; ++i) tmp[i] = *f[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *f[i] = *l[i], *l[i] = *b[i], *b[i] = *r[i], *r[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *f[i] = *r[i], *r[i] = *b[i], *b[i] = *l[i], *l[i] = tmp[i];
    }
  }
}

inline void rotateX(bool dir) {
  static int tmp[4];
  int **f, **l, **r, **b;
  f = F.getLine(2, false, true);
  l = L.getLine(2, false, true);
  r = R.getLine(2, false, true);
  b = B.getLine(2, false, false);
  for (int i = 1; i <= 3; ++i) tmp[i] = *f[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *f[i] = *r[i], *r[i] = *b[i], *b[i] = *l[i], *l[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *f[i] = *l[i], *l[i] = *b[i], *b[i] = *r[i], *r[i] = tmp[i];
    }
  }
}

inline void rotateY(bool dir) {
  static int tmp[4];
  int **f, **u, **b, **d;
  f = F.getLine(2, true, false);
  u = U.getLine(2, true, false);
  b = B.getLine(2, true, false);
  d = D.getLine(2, true, false);
  for (int i = 1; i <= 3; ++i) tmp[i] = *f[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *f[i] = *d[i], *d[i] = *b[i], *b[i] = *u[i], *u[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *f[i] = *u[i], *u[i] = *b[i], *b[i] = *d[i], *d[i] = tmp[i];
    }
  }
}

inline void rotateZ(bool dir) {
  static int tmp[4];
  int **l, **u, **r, **d;
  l = L.getLine(2, true, false);
  u = U.getLine(2, false, true);
  r = R.getLine(2, true, true);
  d = D.getLine(2, false, false);
  for (int i = 1; i <= 3; ++i) tmp[i] = *u[i];
  if (dir) {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *l[i], *l[i] = *d[i], *d[i] = *r[i], *r[i] = tmp[i];
    }
  } else {
    for (int i = 1; i <= 3; ++i) {
      *u[i] = *r[i], *r[i] = *d[i], *d[i] = *l[i], *l[i] = tmp[i];
    }
  }
}

void afunc() { rotateL(false); }
void Afunc() { rotateL(true); }

void bfunc() { rotateY(true); }
void Bfunc() { rotateY(false); }

void cfunc() { rotateR(true); }
void Cfunc() { rotateR(false); }

void dfunc() { rotateF(false); }
void Dfunc() { rotateF(true); }

void efunc() { rotateZ(false); }
void Efunc() { rotateZ(true); }

void ffunc() { rotateB(true); }
void Ffunc() { rotateB(false); }

void jfunc() { rotateD(true); }
void Jfunc() { rotateD(false); }

void hfunc() { rotateU(false); }
void Hfunc() { rotateU(true); }

void ifunc() { rotateX(false); }
void Ifunc() { rotateX(true); }

void (*lfunc[10])() = {afunc, bfunc, cfunc, dfunc, efunc,
                       ffunc, 0,     hfunc, ifunc, jfunc};
void (*ufunc[10])() = {Afunc, Bfunc, Cfunc, Dfunc, Efunc,
                       Ffunc, 0,     Hfunc, Ifunc, Jfunc};

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("cube.in", "r", stdin);
  freopen("cube.out", "w", stdout);
#endif
#endif

  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) scanf("%d", &U.s[i][j]);
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 9; ++j) scanf("%d", &read[i][j]);
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) L.s[i][j] = read[i][j];
  for (int i = 1; i <= 3; ++i)
    for (int j = 4; j <= 6; ++j) F.s[i][j - 3] = read[i][j];
  for (int i = 1; i <= 3; ++i)
    for (int j = 7; j <= 9; ++j) R.s[i][j - 6] = read[i][j];
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) scanf("%d", &D.s[i][j]);
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) scanf("%d", &B.s[i][j]);

  scanf("%s", opt);
  n = strlen(opt);
  for (int i = 0; i < n; ++i) {
    if (isupper(opt[i])) {
      ufunc[opt[i] - 'A']();
    } else {
      lfunc[opt[i] - 'a']();
    }
  }
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) printf("%d ", U.s[i][j]);
    putchar('\n');
  }
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j) read[i][j] = L.s[i][j];
  for (int i = 1; i <= 3; ++i)
    for (int j = 4; j <= 6; ++j) read[i][j] = F.s[i][j - 3];
  for (int i = 1; i <= 3; ++i)
    for (int j = 7; j <= 9; ++j) read[i][j] = R.s[i][j - 6];
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 9; ++j) printf("%d ", read[i][j]);
    putchar('\n');
  }
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) printf("%d ", D.s[i][j]);
    putchar('\n');
  }
  for (int i = 1; i <= 3; ++i) {
    for (int j = 1; j <= 3; ++j) printf("%d ", B.s[i][j]);
    putchar('\n');
  }
  return 0;
}